package com.ruoyi.web.controller.guarantee;

import java.util.List;

import com.ruoyi.guarantee.domain.FzGuarantee;
import com.ruoyi.guarantee.service.IFzGuaranteeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保修管理Controller
 * 
 * @author ruoyi
 * @date 2020-03-13
 */
@Controller
@RequestMapping("/guarantee")
public class FzGuaranteeController extends BaseController
{
    private String prefix = "guarantee/guarantee";

    @Autowired
    private IFzGuaranteeService fzGuaranteeService;

    @RequiresPermissions("guarantee:guarantee:view")
    @GetMapping()
    public String guarantee()
    {
        return prefix + "/guarantee";
    }

    /**
     * 查询保修管理列表
     */
    @RequiresPermissions("guarantee:guarantee:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FzGuarantee fzGuarantee)
    {
        startPage();
        List<FzGuarantee> list = fzGuaranteeService.selectFzGuaranteeList(fzGuarantee);
        return getDataTable(list);
    }

    /**
     * 导出保修管理列表
     */
    @RequiresPermissions("guarantee:guarantee:export")
    @Log(title = "保修管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzGuarantee fzGuarantee)
    {
        List<FzGuarantee> list = fzGuaranteeService.selectFzGuaranteeList(fzGuarantee);
        ExcelUtil<FzGuarantee> util = new ExcelUtil<FzGuarantee>(FzGuarantee.class);
        return util.exportExcel(list, "guarantee");
    }

    /**
     * 新增保修管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存保修管理
     */
    @RequiresPermissions("guarantee:guarantee:add")
    @Log(title = "保修管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzGuarantee fzGuarantee)
    {
        return toAjax(fzGuaranteeService.insertFzGuarantee(fzGuarantee));
    }

    /**
     * 修改保修管理
     */
    @GetMapping("/edit/{guaranteeId}")
    public String edit(@PathVariable("guaranteeId") String guaranteeId, ModelMap mmap)
    {
        FzGuarantee fzGuarantee = fzGuaranteeService.selectFzGuaranteeById(guaranteeId);
        mmap.put("fzGuarantee", fzGuarantee);
        return prefix + "/edit";
    }

    /**
     * 修改保存保修管理
     */
    @RequiresPermissions("guarantee:guarantee:edit")
    @Log(title = "保修管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzGuarantee fzGuarantee)
    {
        return toAjax(fzGuaranteeService.updateFzGuarantee(fzGuarantee));
    }

    /**
     * 删除保修管理
     */
    @RequiresPermissions("guarantee:guarantee:remove")
    @Log(title = "保修管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzGuaranteeService.deleteFzGuaranteeByIds(ids));
    }
}
